package com.itheima.day14.xianchengchi;

public class MyRunnable implements Runnable{

    int  num  = 100;


    @Override
    public void run() {
        while(true){
            if(sendGift()){
                break;
            }
        }
    }

    private  synchronized boolean sendGift() {
        if(num > 10){
            System.out.println(Thread.currentThread().getName()+"正在发送第"+num+"个礼物...");
            num--;
            try {
                Thread.sleep(300);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            return false;
        }else{
            System.out.println(Thread.currentThread().getName()+"没有礼物了...");
            return true;
        }

    }
}
